<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>

	<meta charset="UTF-8">
	<title>管理员登录-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" th:href="@{favicon.ico}" type="image/x-icon" />
    <link rel="stylesheet" href="/static/css/font.css">
	<link rel="stylesheet" href="/static/css/weadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/lib/jquery-2.1.3.min.js"></script>

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">IoT-Agriculture 1.0-管理登录</div>
        <div id="darkbannerwrap"></div>
        <div class="show_login">
            <p>账号</p>
            <input id="account" name="account"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <p>密码</p>
            <input id="password" name="password" lay-verify="required" type="password" class="layui-input">
            <hr class="hr15">
            <input id="login" onclick="login()" value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr15" >
            <input id="regist" onclick="regist()" value="注册" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr20" >
        </div>
        <div class="show_regist" style="display: none">
            <p>账号</p>
            <input id="account_reg" name="account_reg"  type="text" lay-verify="required" class="layui-input" >
            <hr class="hr15">
            <p>密码</p>
            <input id="password_reg" name="password_reg" lay-verify="required" type="password" class="layui-input">
            <hr class="hr15">
            <p>安全码</p>
            <input id="securityno_reg" name="securityno_reg" lay-verify="required" type="password" class="layui-input">
            <hr class="hr15">
            <input id="regist_reg" onclick="regist_reg()" value="注册" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr15">
            <input id="back_reg" onclick="back()" value="返回" lay-submit lay-filter="login" style="width:100%;" type="submit">
            <hr class="hr15" >
        </div>
    </div>

    <script type="text/javascript" th:inline="javascript">

        layui.extend({
            admin: '/static/js/admin'
        });

        layui.use(['form','admin'], function(){
            var admin = layui.admin;
        });

        function login() {
            var account = $("#account").val();
            var password = $("#password").val();
            $.ajax({
                type : "POST",
                url : "/admin/login_check",
                data : {
                    "account" : account,
                    "password" : password
                },
                async : false,
                cache : false,
                success : function(data) {
                    if (JSON.parse(data).msg == "success") {
                        window.location.href = "/admin/login_success";
                    }else {
                        alert("账号密码错误");
                    }
                },
                error : function() {
                    alert("系统错误");
                }
            });
        }

        function regist() {
            $(".show_login").css("display", "none");
            $(".show_regist").css("display", "block");
        }

        function back(){
            $(".show_login").css("display", "block");
            $(".show_regist").css("display", "none");
        }

        function regist_reg() {
            var account = $("#account_reg").val();
            var password = $("#password_reg").val();
            var securityno = $("#securityno_reg").val();
            if(account == "" || account == undefined || account == null ||
                password == "" || password == undefined || password == null ||
                securityno == "" || securityno == undefined || securityno == null){
                alert("请输入完整信息");
            } else {
                $.ajax({
                    type : "POST",
                    url : "/admin/regist",
                    data : {
                        "account" : account,
                        "password" : password,
                        "securityno" : securityno
                    },
                    async : false,
                    cache : false,
                    success : function(data) {
                        if (JSON.parse(data).msg == "success") {
                            alert("注册成功");
                            //返回到登录
                            back();
                        }else {
                            alert("注册失败");
                        }
                    },
                    error : function() {
                        alert("系统错误");
                    }
                });
            }
        }

    </script>  
    <!-- 底部结束 -->
</body>
</html>